package com.hex.liyue.usermodule.presenter;

import android.text.TextUtils;

import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.commonmodule.utils.RegularUtils;

/**
 * 这是一个忘记密码的业务类
 * Created by yukoyuan on 16/6/14.
 */
public class ForgetPwdPresenter {
    IForgetPwdView iForgetPwdView;

    public ForgetPwdPresenter(IForgetPwdView iForgetPwdView) {
        this.iForgetPwdView = iForgetPwdView;
    }

    /**
     * 这是一个获取验证码的方法
     */
    public void getvcode() {
        //判断手机号是否正确
        if (!RegularUtils.phone(iForgetPwdView.getPhone())) {
            iForgetPwdView.showT("请输入正确的手机号");
            return;
        }
        iForgetPwdView.delyTime(120);
        HttpManager.getInstance().getvcode(iForgetPwdView.getPhone(), 3, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iForgetPwdView.showT("发送成功");
                iForgetPwdView.startLoginFragment();
            }

            @Override
            public void onFailure(String responseresult) {
                iForgetPwdView.showT(responseresult);
            }
        });
    }

    /**
     * 这是个修改密码的方法
     */
    public void resetPwd() {
        //手机号
        if (!RegularUtils.phone(iForgetPwdView.getPhone())) {
            iForgetPwdView.showT("请输入正确的手机号");
            return;
        }
        //验证码
        if (TextUtils.isEmpty(iForgetPwdView.getVcode())) {
            iForgetPwdView.showT("验证码不能为空");
            return;
        }
        //密码
        if (TextUtils.isEmpty(iForgetPwdView.getPwd())) {
            iForgetPwdView.showT("密码不能为空");
            return;
        }
        iForgetPwdView.showLod("请求中...");
        HttpManager.getInstance().resetPwd(iForgetPwdView.getPhone(), iForgetPwdView.getVcode(), iForgetPwdView.getPwd(), new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iForgetPwdView.showT("修改成功");
                iForgetPwdView.startLoginFragment();
                iForgetPwdView.closeLod();
            }

            @Override
            public void onFailure(String responseresult) {
                iForgetPwdView.showT(responseresult);
                iForgetPwdView.closeLod();
            }
        });
    }
}
